package com.yshkj.payment.entity;

import lombok.Data;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 唐旭 on 2016/10/1.
 */
@Entity
@Table
@Data
public class Privilege extends BaseDomain {
    //权限名称
    @Column
    private String name;
    //权限图标
    @Column
    private String icon;
    //权限对应的url
    @Column
    private String url;
    //权限对应的label
    @Column
    private String label;
    //顺序
    //顺序越小,排在越前面
    @Column
    private int ordered;
    //父权限
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent")
    private Privilege parent;
    //子权限
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "parent")
    private List<Privilege> subPrivileges = new ArrayList<>();

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        Privilege privilege = (Privilege) o;

        return name.equals(privilege.name);

    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + name.hashCode();
        return result;
    }
}
